package com.visikard.ui.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.visikard.item.ItemGiftKard;
import com.visikard.ui.R;
import com.visikard.utility.BitmapUtils;
import com.visikard.utility.UILImageUtils;
import com.visikard.utility.Utils;
import com.visikard.widget.ResizableImageView;

public class GiftSpecialsAdapter extends BaseAdapter{

	private ArrayList<ItemGiftKard> mItems;
	private Context mContext;

	public GiftSpecialsAdapter(Context context, ArrayList<ItemGiftKard> items) {
		mContext = context;
		mItems = items;
	}

	@Override
	public int getCount() {
		return mItems.size();
	}

	@Override
	public ItemGiftKard getItem(int position) {
		if (position < mItems.size() && position > -1)
			return mItems.get(position);
		return new ItemGiftKard();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View currentView, ViewGroup arg2) {
		Holder holder = null;
		if (currentView == null) {
			currentView = View.inflate(mContext, R.layout.gift_spcials_item, null);
			holder = new Holder();
			
			holder.rootView = (LinearLayout) currentView.findViewById(R.id.wallet_coupon_content_box);
			Utils.overrideFonts(holder.rootView);
			
			holder.imageCoupon = (ResizableImageView) currentView.findViewById(R.id.coupon_kard_image);

			holder.salesOff = (TextView) currentView.findViewById(R.id.coupon_discount);
			holder.salesOffContent = (TextView) currentView.findViewById(R.id.coupon_discount_content);
			
			currentView.setTag(holder);
		} else {
			holder = (Holder) currentView.getTag();
		}
		
		ItemGiftKard currentItem = mItems.get(position);
//		ImageLoader.getInstance(mContext).loadImage(holder.imageCoupon, currentItem.getImageKard(),
//				 0, BitmapUtils.ROUND_NONE, 0, 0, 0);
		UILImageUtils.loadImage(holder.imageCoupon, //image view
				currentItem.getImageKard(), //url
				0, //size of view
				BitmapUtils.ROUND_NONE, //round all 
				0, // round size
				0, //shadow
				R.drawable.kard_shadow_default_horizontal, //shadow resource 
				0, 0); 
		holder.salesOff.setText(currentItem.getTextImage1());
		holder.salesOffContent.setText(currentItem.getCampaignDetail());

		return currentView;
	}

	class Holder {
		
		LinearLayout rootView;
		ResizableImageView imageCoupon;
		TextView salesOff;
		TextView salesOffContent;
		
	}

}
